#include "Shaders.h"
#include "Muzzy A Wrappers\D3DManager.h"
#include <iostream>


Shaders::Shaders(void)
{
}


Shaders::~Shaders(void)
{
}

Shaders* Shaders::getInstance()
{
	static Shaders thisInstance;

	return &thisInstance;
}

void Shaders::Initialize()
{
	// Declarations
	Shader	pDefault	= nullptr;
	Shader	pLights		= nullptr;

	// Load the shaders
	D3DXCreateEffectFromFileA(D3DManager::getInstance()->getDevice(),"Assets/Shaders/DefaultShader.fx",0,0,0,0,&pDefault,0);
	D3DXCreateEffectFromFileA(D3DManager::getInstance()->getDevice(),"Assets/Shaders/LightShader.fx",0,0,0,0,&pLights,0);

	// Add the shaders to the list
	m_Shaders.push_back(pDefault);
	m_Shaders.push_back(pLights);

	// Get the handle for the parameters to increase fps
	m_hMVP			= new char[5];
	m_hTexture		= new char[9];
	m_hTexCoord		= new char[10];
	m_hColorMask	= new char[11];

	strcpy_s(m_hMVP,5,"gMVP");
	strcpy_s(m_hTexture,9,"gTexture");
	strcpy_s(m_hTexCoord,10,"gTexCoord");
	strcpy_s(m_hColorMask,11,"gColorMask");

	// Set the active shader to the default shader
	m_pActiveShader	= pDefault;
}

void Shaders::Shutdown()
{
	m_pActiveShader	= nullptr;

	for(unsigned i = 0;i < m_Shaders.size();++i)
		SAFE_RELEASE(m_Shaders[i]);

	m_Shaders.clear();

	delete [] m_hMVP;
	delete [] m_hTexture;
	delete [] m_hTexCoord;
	delete [] m_hColorMask;
}